package top.yangbuyi.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.yangbuyi.acpect.annotaction.Log;
import top.yangbuyi.acpect.enums.BusinessType;
import top.yangbuyi.dto.CheckItemDto;
import top.yangbuyi.service.impl.CheckItemService;
import top.yangbuyi.utils.ShiroSecurityUtils;
import top.yangbuyi.vo.AjaxResult;
import top.yangbuyi.vo.DataGridView;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;


/**
 * @description: 杨不易网站:www.yangbuyi.top
 * @program: yangbuyiopenHis2020
 * @ClassName: CheckItemController
 * @create: 2020-09-10 23:02
 * @author: yangbuyi
 * @since： JDK1.8
 * @CheckItemController: 检查项目$
 **/

@RestController
@RequestMapping("system/checkItem")
public class CheckItemController {

	  @Autowired
	  private CheckItemService checkItemService;

	  /**
	   * 分页查询
	   */
	  @GetMapping("listCheckItemForPage")
	  public AjaxResult listCheckItemForPage(CheckItemDto checkItemDto) {
			DataGridView gridView = this.checkItemService.listCheckItemPage(checkItemDto);
			return AjaxResult.success("查询成功", gridView.getData(), gridView.getTotal());
	  }

	  /**
	   * 查询全部可用的检查项目
	   *
	   * @param checkItemDto
	   * @return
	   */
	  @GetMapping("selectAllCheckItem")
	  public AjaxResult selectAllCheckItem() {
			return AjaxResult.success(this.checkItemService.selectAllCheckItem());
	  }

	  /**
	   * 添加
	   */
	  @PostMapping("addCheckItem")
	  @Log(title = "添加通知检查项目", businessType = BusinessType.INSERT)
	  public AjaxResult addCheckItem(@Validated CheckItemDto checkItemDto) {
			checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
			return AjaxResult.toAjax(this.checkItemService.addCheckItem(checkItemDto));
	  }

	  /**
	   * 修改
	   */
	  @PutMapping("updateCheckItem")
	  @Log(title = "修改检查项目", businessType = BusinessType.UPDATE)
	  public AjaxResult updateCheckItem(@Validated CheckItemDto checkItemDto) {
			checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
			return AjaxResult.toAjax(this.checkItemService.updateCheckItem(checkItemDto));
	  }


	  /**
	   * 根据ID查询一个通知检查项目信息
	   */
	  @GetMapping("getCheckItemById/{checkItemId}")
	  public AjaxResult getCheckItemById(@PathVariable @Validated @NotNull(message = "检查项目ID不能为空") Long checkItemId) {
			return AjaxResult.success(this.checkItemService.getOne(checkItemId));
	  }

	  /**
	   * 删除
	   */
	  @DeleteMapping("deleteCheckItemByIds/{checkItemIds}")
	  @Log(title = "删除检查项目", businessType = BusinessType.DELETE)
	  public AjaxResult deleteCheckItemByIds(@PathVariable @Validated @NotEmpty(message = "要删除的ID不能为空") Long[] checkItemIds) {
			return AjaxResult.toAjax(this.checkItemService.deleteCheckItemByIds(checkItemIds));
	  }


}
